package com.yatuhashi.manual.mhp3;

import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;

import com.yatuhashi.manual.mhp3.custom.BaseGridAdapter;

public class TopActivity extends BaseActivity {
    private static final int MENU_MONSTER_LIST = 0;
    private static final int MENU_QUEST_LIST = 1;
    private static final int MENU_WEAPON_LIST = 2;
    private static final int MENU_PROTECTOR_LIST = 3;
    private static final int MENU_SKILL_LIST = 4;
    private static final int MENU_ITEM_LIST = 5;
    private static final int MENU_MAP = 6;
    
    private static final int[] DRAWABLES = {
        R.drawable.no_image,
        R.drawable.no_image,
//        R.drawable.no_image,
//        R.drawable.no_image,
//        R.drawable.no_image,
//        R.drawable.no_image,
//        R.drawable.no_image,
//        R.drawable.no_image,
    };
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.top_activity);
        
        initHeader(getString(R.string.app_name));
        
        BaseGridAdapter adapter = new BaseGridAdapter(this);
        Resources res = getResources();
        for(int i=0; i<DRAWABLES.length; i++) {
            Bitmap bmp = BitmapFactory.decodeResource(res, DRAWABLES[i]);
            adapter.add(bmp);
        }
        
        GridView gridView = (GridView) findViewById(R.id.grid_view);
        gridView.setAdapter(adapter);
        gridView.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                switch (position) {
                case MENU_MONSTER_LIST:
                    goToMonsterInfo();
                    break;
                case MENU_QUEST_LIST:
                    goToQuestInfo();
                    break;
                case MENU_WEAPON_LIST:
                case MENU_PROTECTOR_LIST:
                case MENU_SKILL_LIST:
                case MENU_ITEM_LIST:
                case MENU_MAP:
                default:
                    toast(Integer.toString(position));
                    break;
                }
            }
        });
        
//        LinearLayout layout = (LinearLayout) findViewById(R.id.ad_layout);
//        AdView adView = new AdView(this, AdSize.BANNER, "Publisher id");
        
    }
    
    private void goToMonsterInfo() {
        Intent intent = new Intent(this, MonsterListActivity.class);
        startActivity(intent);
    }
    
    private void goToQuestInfo() {
        Intent intent = new Intent(this, QuestListActivity.class);
        startActivity(intent);
    }
    
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
        case R.id.top_icon:
            toast("top icon");
            break;
        case R.id.app_title:
            toast("app title");
            break;
        case R.id.left_btn:
            toast("search button");
            break;
        case R.id.right_btn:
            toast("share button");
            break;
        }
    }
}
